#!/bin/bash

sp1_pretty_name=(
"Kylin V10 Professional"
"Kylin V10 SP1"
"Kylin V10.1"
)

sp1_dist_id=(
"Kylin-Desktop-V10-Professional"
"Kylin-Desktop-V10-SP1"
"Kylin-Desktop-V10.1"
)

#获取LICENSE中OSNAME值
get_os_name(){
if [ -f "/etc/LICENSE" ]; then
	cat /etc/LICENSE | 
	while read line
	do
		str="OSNAME"
		if [[ $line == $str* ]];then #取出包含OSNAME的行
			echo ${line##*:}
			break
		fi
	done
fi
}

#获取/etc/os-release中的PRETTY_NAME
get_pretty_name(){
	if [ -f "/etc/os-release-variant" ];then
		path="/etc/os-release-variant"
	else
		path="/etc/os-release"
	fi
	cat $path |
	while read line
	do
		str="PRETTY_NAME"
		if [[ $line == $str* ]];then
			echo ${line##*=}| sed 's/"//g'
			break
		fi
	done
}

#获取/etc/.kyinfo中的dist_id
get_dist_id(){
	cat "/etc/.kyinfo" |
	while read line
	do
		if [[ "$line" == dist_id* ]];then
			echo ${line##*=}
			break
		fi
	done
}

#版本校验
os_check(){
	distid=$(get_dist_id)
	prettyname=$(get_pretty_name)
	if [ -n "$1" ];then
		if [ -f "/etc/os-release-variant" ];then
			if [ "$prettyname" == "$1" ];then
				return 0
			fi
		else
			if [[ "$(echo $1 | sed 's/ //g')" == KylinV10SP* ]] || [ "$1" == "Kylin V10 Professional" ] || [ "$1" == "Kylin V10.1" ];then
				return 0
			fi
		fi
	else
		if [[ "$distid" == Kylin-Desktop-V10-Professional* ]] || [[ "$distid" == Kylin-Desktop-V10-SP* ]] || [[ "$distid" == Kylin-Desktop-V10.1* ]];then
			return 0
		fi

	fi
	return 1
}

osname=$(get_os_name)
os_check "$osname"
exit $?
